package com.teachoa.bean;

import java.util.List;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record;
import com.teachoa.constant.Global;

public class Order extends Model<Order> {

	/**
	 * 
	 */
	private static final long serialVersionUID = -5043627127633077617L;
	
	public static final Order dao = new Order();
	
	public List<Order> findTasksByUserId(String userId) {
		String sql = "select * from `order` where status = 1 and user_id like ?";
		return Order.dao.find(sql, "%"+userId+"%");
	}
	
	public Page<Record> findAuditTasksByTeacherId(int pageNo, String userId) {
		String prefix = "SELECT a. NAME AS pname, b. NAME AS uname,e.* ";
		String sql = "FROM project a INNER JOIN uncertain b ON a.uncertain_id = b.id "
				+ "INNER JOIN (SELECT d.order_id, c.project_id,	d.flag, d.task_id, "
				+ "d.user_name FROM	user_task c "
				+ "JOIN order_log d ON c.task_id = d.task_id WHERE d.flag IS NULL "
				+ "AND c.is_current_node = 1) e ON a.id = e.project_id WHERE b.user_id =?";
		return Db.paginate(pageNo, Global.pageSize, prefix, sql, userId);
	}
	
}